﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace fabao.Common.Util
{
    public class NumberHelper
    {
        /// <summary>
        /// 获取随机数(hash码防止并发重复)
        /// </summary>
        /// <param name="minValue"></param>
        /// <param name="maxValue"></param>
        /// <returns></returns>
        public static int GetRandomCode(int minValue, int maxValue)
        {
            int seed = Guid.NewGuid().GetHashCode();
            Random random = new Random(seed);
            return random.Next(minValue, maxValue);
        }

        /// <summary>
        /// 判断一个数最多有两位小数
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static bool AtMostTwoDecimalPlaces(decimal value)
        {
            return System.Text.RegularExpressions.Regex.IsMatch(value.ToString(), @"^\d+(.\d{0,2})?$");
        }
    }
}
